home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
090
/
byte1286.arc
/
AITKEN.BAS
next >
Wrap
BASIC Source File
|
1986-10-29
|
3KB
|
87 lines
100 DEFDBL A-H,L,O-Z
110 REM Use EPS=1E-6 if functions are single precision.
120 EPS=1E-10
130 SQT3=SQR(3)
140 DIM TABLE(20)
150 LG10=LOG(10)
160 DEF FNL10(X)=LOG(X)/LG10
170 F$="f(x)=SQR(EXP(x)-1)/SIN(x)"
180 DEF FNF(X)=SQR(EXP(X)-1)/SIN(X)
190 T1$="###### #####.########## #### ---"
200 T2$="###### #####.########## #### ###"
210 T3$="###### #####.########## ---"
220 T4$="###### #####.########## ###"
230 PRINT "Approximating the integral of the function:"
240 PRINT " "; F$
250 INPUT "Number of lines in Gauss column (>1)";KL
260 INPUT "Lower limit for integral";A
270 INPUT "Upper limit for integral";B
280 IF B<=A THEN PRINT "Error. Lower limit <= upper limit.": STOP
290 PRINT
300 GOSUB 410
310 PRINT
320 FOR J=1 TO 20
330 INPUT "Enter 1 for next Aitken column, 0 to quit";CQ
340 IF CQ=0 THEN J=20: GOTO 390
350 GOSUB 760
360 PRINT
370 KL=KL-2
380 IF KL<3 THEN J=20
390 NEXT J
400 END
410 IF KL<1 THEN PRINT "Error in Gauss subroutine: KL<1.": STOP
420 NLINES=KL
430 NSUBS=1
440 NFUNCT=0
450 PRINT "Gaussian integration table for the function"
460 PRINT F$; ", for x= ";A; " to ";B;"."
470 PRINT "Table contains ";NLINES; " lines."
480 PRINT
490 FOR JLINE=1 TO NLINES
500 XH=(B-A)/NSUBS
510 XH2=XH/2
520 XR=XH2/SQT3
530 START1=A-XH2-XR
540 START2=A-XH2+XR
550 SUM=0
560 FOR K=1 TO NSUBS
570 SUM=SUM+FNF(START1+K*XH)+FNF(START2+K*XH)
580 NEXT K
590 SUM=SUM*XH2
600 NFUNCT=NFUNCT+2*NSUBS
610 IF JLINE>1 THEN 650
620 PRINT " N Gauss NF Est.S.D."
630 PRINT USING T1$; NSUBS,SUM,NFUNCT
640 GOTO 720
650 RELERR=EPS
660 IF SUM<>0 THEN RELERR=ABS(TABLE(JLINE-1)-SUM)/ABS(SUM)
670 IF SUM=0 AND TABLE(JLINE-1)<>0 THEN RELERR=ABS(TABLE(JLINE-1)-SUM)/ABS(TABLE(JLINE-1))
680 IF RELERR<=0 THEN RELERR=EPS
690 NUMSD=-FNL10(RELERR)
700 IF NUMSD<0 THEN NUMSD=0
710 PRINT USING T2$;NSUBS,SUM,NFUNCT,NUMSD
720 NSUBS=2*NSUBS
730 TABLE(JLINE)=SUM
740 NEXT JLINE
750 RETURN
760 IF KL<3 THEN PRINT "Error in Aitken: KL<3.": STOP
770 KLM2=KL-2
780 PRINT: PRINT "Aitken column. ";KLM2;" entries."
790 PRINT: PRINT " Line Aitken Est.S.D.
800 KLM1=KL-1
810 FOR JLINE=2 TO KLM1
820 TOP=(TABLE(JLINE+1)-TABLE(JLINE))^2
830 BOT=TABLE(JLINE+1)-2*TABLE(JLINE)+TABLE(JLINE-1)
840 IF BOT=0 THEN TABLE(JLINE-1)=TABLE(JLINE+1) ELSE TABLE(JLINE-1)=TABLE(JLINE+1)-TOP/BOT
850 JLM1=JLINE-1
860 IF JLINE<=2 THEN PRINT USING T3$;JLM1,TABLE(JLM1): GOTO 940
870 RELERR=EPS
880 IF TABLE(JLM1)<>0 THEN RELERR=ABS(TABLE(JLM1-1)-TABLE(JLM1))/ABS(TABLE(JLM1))
890 IF TABLE(JLM1)=0 AND TABLE(JLM1-1)<>0 THEN RELERR=ABS(TABLE(JLM1-1)-TABLE(JLM1))/ABS(TABLE(JLM1-1))
900 IF RELERR<=0 THEN RELERR=EPS
910 NUMSD=-FNL10(RELERR)
920 IF NUMSD<0 THEN NUMSD=0
930 PRINT USING T4$;JLM1;TABLE(JLM1);NUMSD
940 NEXT JLINE
950 RETURN